package com.zls.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zls.blockHandler.GlobalBlockHandler;
import com.zls.fallback.GlobalFallback;
import com.zls.feign.UserFeign;
import com.zls.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerController {
    @Autowired
    private UserFeign userFeign;

    @RequestMapping(value = "/consumer/getUserById")
    @SentinelResource(value = "getUserById",
            blockHandlerClass = GlobalBlockHandler.class,
            blockHandler = "blockHandlerMethod",
            fallbackClass = GlobalFallback.class,
            fallback = "fallbackMethod")
    public User getUserById(@RequestParam("id") Integer id,String nam) {
//        try {
//            Thread.sleep(500);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return userFeign.getUserById(id);
    }

    @RequestMapping(value = "/test")
    public User test(){
        return userFeign.getUserById(1);
    }

//    public User blockHandlerMethod(Integer id, String nam, BlockException e){
//        return new User(id,"this is blockHandlerMethod of " + nam ,0);
//    }
}
